package com.ak.kaoyan.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {

    //预编译正则表达式,用来匹配源码字符串中的类名
    private static final Pattern CLASS_PATTERN = Pattern.compile("class\\s+([$_a-zA-Z][$_a-zA-Z0-9]*)\\s*");

    public static String getClassName(String code) {
        Matcher matcher = CLASS_PATTERN.matcher(code);
        String className;
        if (matcher.find()) {
            className = matcher.group(1);
        } else {
            return null;
        }
        return className;
    }
}
